package LeetCode;

/**
 * @Classname LC124
 * @Description [Tree]//  https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/
 * @Date 2021/4/19 10:27
 * @Created by yin
 */
public class LC124 {
    private int ans = 0;
    public int maxPathSum(TreeNode root) {
        sun(root);
        return ans;
    }
    public int sun(TreeNode root){
        if(root==null) return 0;
        int left = Math.max(0,sun(root.left));
        int right = Math.max(0,sun(root.right));
        ans = Math.max(ans,left+right+root.val);
        return Math.max(left,right)+root.val;
    }
}
